//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "VegaBumpCollection.h"
using namespace Cephei::QL::Models::Marketmodels::Pathwisegreeks;
#include <gen/QL/Models/Marketmodels/Pathwisegreeks/VegaBumpCluster.h>
#include <gen/QL/Models/Marketmodels/MarketModel.h>
using namespace Cephei::QL::Models::Marketmodels;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Models::Marketmodels::Pathwisegreeks::CVegaBumpCollection::CVegaBumpCollection (Cephei::Core::IVector<Cephei::QL::Models::Marketmodels::Pathwisegreeks::IVegaBumpCluster^>^ allBumps, Cephei::QL::Models::Marketmodels::IMarketModel^ volStructure) 
{
	_pSpinlock = new boost::detail::spinlock ();
    CMarketModel^ _CvolStructure;
    try
    {
#ifdef HANDLE
        _phVegaBumpCollection = NULL;
#endif
        allBumps ->Lock ();
        INativeVector<Cephei::QL::Models::Marketmodels::Pathwisegreeks::IVegaBumpCluster^>^ _NCIallBumps = allBumps->getFeature (NativeFeature::Value);
        CVegaBumpClusterVector^ _NCallBumps = safe_cast<CVegaBumpClusterVector^>(_NCIallBumps);
        std::vector<QuantLib::VegaBumpCluster>& _allBumps = static_cast<std::vector<QuantLib::VegaBumpCluster>&> (_NCallBumps->GetReference ());
        _CvolStructure = safe_cast<CMarketModel^> (volStructure);
        _CvolStructure->Lock();
        boost::shared_ptr<QuantLib::MarketModel>& _volStructure = static_cast<boost::shared_ptr<QuantLib::MarketModel>&> (_CvolStructure->GetShared ()); 
        _ppVegaBumpCollection = new boost::shared_ptr<QuantLib::VegaBumpCollection> (new QuantLib::VegaBumpCollection ( _allBumps,  _volStructure ));
        
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (allBumps != nullptr) allBumps->Unlock();    //not optional
        if (_CvolStructure != nullptr) _CvolStructure->Unlock();
    }
}
Cephei::QL::Models::Marketmodels::Pathwisegreeks::CVegaBumpCollection::CVegaBumpCollection (Cephei::QL::Models::Marketmodels::IMarketModel^ volStructure, Microsoft::FSharp::Core::FSharpOption<Boolean>^ allowFactorwiseBumping) 
{
	_pSpinlock = new boost::detail::spinlock ();
    CMarketModel^ _CvolStructure;
    try
    {
#ifdef HANDLE
        _phVegaBumpCollection = NULL;
#endif
        _CvolStructure = safe_cast<CMarketModel^> (volStructure);
        _CvolStructure->Lock();
        boost::shared_ptr<QuantLib::MarketModel>& _volStructure = static_cast<boost::shared_ptr<QuantLib::MarketModel>&> (_CvolStructure->GetShared ()); 
        bool _allowFactorwiseBumping = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (allowFactorwiseBumping) ? (bool)ValueHelper::Convert (allowFactorwiseBumping->Value) : true); //4
        _ppVegaBumpCollection = new boost::shared_ptr<QuantLib::VegaBumpCollection> (new QuantLib::VegaBumpCollection ( _volStructure,  _allowFactorwiseBumping ));
        
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (_CvolStructure != nullptr) _CvolStructure->Unlock();
    }
}
Cephei::QL::Models::Marketmodels::Pathwisegreeks::CVegaBumpCollection::CVegaBumpCollection (boost::shared_ptr<QuantLib::VegaBumpCollection>& childNative, Object^ owner) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phVegaBumpCollection = NULL;
#endif
	_ppVegaBumpCollection = &childNative;
    
}
Cephei::QL::Models::Marketmodels::Pathwisegreeks::CVegaBumpCollection::CVegaBumpCollection (QuantLib::VegaBumpCollection& childNative, Object^ owner) 
{
#ifdef HANDLE
	_phVegaBumpCollection = NULL;
#endif
	_ppVegaBumpCollection = new boost::shared_ptr<QuantLib::VegaBumpCollection> (&childNative);
    
    _VegaBumpCollectionOwner = owner;
    
}

Cephei::QL::Models::Marketmodels::Pathwisegreeks::CVegaBumpCollection::CVegaBumpCollection (CVegaBumpCollection^ copy) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phVegaBumpCollection = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppVegaBumpCollection = new boost::shared_ptr<QuantLib::VegaBumpCollection> (copy->GetShared());
        
    }
}
Cephei::QL::Models::Marketmodels::Pathwisegreeks::CVegaBumpCollection::CVegaBumpCollection (PLATFORM::Type^ t) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phVegaBumpCollection = NULL;
#endif
	if (!t->IsSubclassOf(CVegaBumpCollection::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Models::Marketmodels::Pathwisegreeks::CVegaBumpCollection::CVegaBumpCollection (QuantLib::Handle<QuantLib::VegaBumpCollection>& childNative, Object^ owner)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phVegaBumpCollection = &childNative;
	_ppVegaBumpCollection = &static_cast<boost::shared_ptr<QuantLib::VegaBumpCollection>>(childNative.currentLink());
    
    _VegaBumpCollectionOwner = owner;
}
Cephei::QL::Models::Marketmodels::Pathwisegreeks::CVegaBumpCollection::CVegaBumpCollection (QuantLib::Handle<QuantLib::VegaBumpCollection> childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phVegaBumpCollection = &childNative;
	_ppVegaBumpCollection = &static_cast<boost::shared_ptr<QuantLib::VegaBumpCollection>>(childNative.currentLink());
    
}
#endif
#ifdef STRUCT
Cephei::QL::Models::Marketmodels::Pathwisegreeks::CVegaBumpCollection::CVegaBumpCollection (QuantLib::VegaBumpCollection childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phVegaBumpCollection = NULL;
#endif
	_ppVegaBumpCollection = new boost::shared_ptr<QuantLib::VegaBumpCollection> (new QuantLib::VegaBumpCollection (childNative));
    
}
#endif

Cephei::QL::Models::Marketmodels::Pathwisegreeks::CVegaBumpCollection::~CVegaBumpCollection ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
        _pSpinlock = NULL;
    }
    if (_ppVegaBumpCollection != NULL)
    {
	    delete _ppVegaBumpCollection;
        _ppVegaBumpCollection = NULL;
    }
}
Cephei::QL::Models::Marketmodels::Pathwisegreeks::CVegaBumpCollection::!CVegaBumpCollection ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
    }
    if (_ppVegaBumpCollection != NULL)
    {
	    delete _ppVegaBumpCollection;
    }
}
QuantLib::VegaBumpCollection& Cephei::QL::Models::Marketmodels::Pathwisegreeks::CVegaBumpCollection::GetReference ()
{
    if (_ppVegaBumpCollection == NULL) throw REFNEW NativeNullException ();
	return **_ppVegaBumpCollection;
}
boost::shared_ptr<QuantLib::VegaBumpCollection>& Cephei::QL::Models::Marketmodels::Pathwisegreeks::CVegaBumpCollection::GetShared ()
{
    if (_ppVegaBumpCollection == NULL) throw REFNEW NativeNullException ();
	return *_ppVegaBumpCollection;
}
QuantLib::VegaBumpCollection* Cephei::QL::Models::Marketmodels::Pathwisegreeks::CVegaBumpCollection::GetPointer ()
{
    if (_ppVegaBumpCollection == NULL) throw REFNEW NativeNullException ();
	return &**_ppVegaBumpCollection;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::VegaBumpCollection>& Cephei::QL::Models::Marketmodels::Pathwisegreeks::CVegaBumpCollection::GetHandle ()
{
	if (_phVegaBumpCollection == NULL)
	{
		_phVegaBumpCollection = new Handle<QuantLib::VegaBumpCollection> (*_ppVegaBumpCollection);
	}
	return *_phVegaBumpCollection;
}
#endif
bool Cephei::QL::Models::Marketmodels::Pathwisegreeks::CVegaBumpCollection::HasNative () 
{
	return (_ppVegaBumpCollection != NULL);
}

Cephei::Core::IVector<Cephei::QL::Models::Marketmodels::Pathwisegreeks::IVegaBumpCluster^>^ Cephei::QL::Models::Marketmodels::Pathwisegreeks::CVegaBumpCollection::AllBumps::get ()
{
    try
    {
    	std::vector<QuantLib::VegaBumpCluster>& _rv = (std::vector<QuantLib::VegaBumpCluster>&)(*_ppVegaBumpCollection)->allBumps ( );   
        CoVector<Cephei::QL::Models::Marketmodels::Pathwisegreeks::IVegaBumpCluster^>^ _nrv = REFNEW CoVector<Cephei::QL::Models::Marketmodels::Pathwisegreeks::IVegaBumpCluster^>(REFNEW CVegaBumpClusterVector (_rv, this));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Models::Marketmodels::IMarketModel^ Cephei::QL::Models::Marketmodels::Pathwisegreeks::CVegaBumpCollection::AssociatedModel::get ()
{
    try
    {
    	boost::shared_ptr<QuantLib::MarketModel>& _rv = (boost::shared_ptr<QuantLib::MarketModel>&)(*_ppVegaBumpCollection)->associatedModel ( );   
        Cephei::QL::Models::Marketmodels::CMarketModel^ _nrv = REFNEW Cephei::QL::Models::Marketmodels::CMarketModel (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Boolean Cephei::QL::Models::Marketmodels::Pathwisegreeks::CVegaBumpCollection::IsFull::get ()
{
    try
    {
    	bool _rv = (bool)(*_ppVegaBumpCollection)->isFull ( );   
        Boolean _nrv = (Boolean)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Boolean Cephei::QL::Models::Marketmodels::Pathwisegreeks::CVegaBumpCollection::IsNonOverlapping::get ()
{
    try
    {
    	bool _rv = (bool)(*_ppVegaBumpCollection)->isNonOverlapping ( );   
        Boolean _nrv = (Boolean)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Boolean Cephei::QL::Models::Marketmodels::Pathwisegreeks::CVegaBumpCollection::IsSensible::get ()
{
    try
    {
    	bool _rv = (bool)(*_ppVegaBumpCollection)->isSensible ( );   
        Boolean _nrv = (Boolean)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
UInt64 Cephei::QL::Models::Marketmodels::Pathwisegreeks::CVegaBumpCollection::NumberBumps::get ()
{
    try
    {
    	QuantLib::Size _rv = (QuantLib::Size)(*_ppVegaBumpCollection)->numberBumps ( );   
        UInt64 _nrv = _rv; //c1
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Models::Marketmodels::Pathwisegreeks::IVegaBumpCollection^ Cephei::QL::Models::Marketmodels::Pathwisegreeks::CVegaBumpCollection_Factory::Create (Cephei::Core::IVector<Cephei::QL::Models::Marketmodels::Pathwisegreeks::IVegaBumpCluster^>^ allBumps, Cephei::QL::Models::Marketmodels::IMarketModel^ volStructure)
{
    return REFNEW CVegaBumpCollection ( allBumps,  volStructure);
}
Cephei::QL::Models::Marketmodels::Pathwisegreeks::IVegaBumpCollection^ Cephei::QL::Models::Marketmodels::Pathwisegreeks::CVegaBumpCollection_Factory::Create (Cephei::QL::Models::Marketmodels::IMarketModel^ volStructure, Microsoft::FSharp::Core::FSharpOption<Boolean>^ allowFactorwiseBumping)
{
    return REFNEW CVegaBumpCollection ( volStructure,  allowFactorwiseBumping);
}
